package com.uyii.springbootmongo.repository;

import com.uyii.springbootmongo.document.User;
import com.uyii.springbootmongo.vo.userVo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends MongoRepository<User, String> {

    @Query("{ 'age' : { $gt: ?0 } }")
    List<User> findByAgeGreaterThan(int age);

    @Query(value = "{}", fields = "{ 'name' : 1, 'age' : 1, 'id' : 0 }")
    List<userVo> findAllNamesAndAges();
}